﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using Models;

namespace DAL
{
    public class AddressService
    {
        //用户收货地址
        //新增
        public  bool addadd(Address address)
        {
            /// <summary>
            /// 新增收获地址
            /// </summary>
            string sql = string.Format("insert address values('{0}','{1}','{2}','{3}','{4}')",
                address.Addres,address.Name,address.Phone,address.Userid,address.Rule);
            return DBhelper.ex(sql);
        }
        //当前用户的地址
        public SqlDataReader get(int id)
        {
            string sql = "select * from address where userid="+id+" order by [rule] desc";
            return DBhelper.DataReader(sql);
        }
        //修改
        public  bool update(Address address)
        {
            string sql = string.Format("update address set address='{0}',name='{1}',phone='{2}',userid='{3}',rule='{4}' where id='{5}'",
                address.Addres,address.Name,address.Phone,address.Userid,address.Rule,address.Id);
            return DBhelper.ex(sql);
        }
        //修改默认
        public bool uprule(int id)
        {
            string sql = "update address set [rule]=1 where id="+id;
            return DBhelper.ex(sql);
        }
        //默认清空
        public bool upup()
        {
            string sql = "update address set [rule]=0";
            return DBhelper.ex(sql);
        }
        //删除
        public  bool del(int id)
        {
            string sql = "delete address where id="+id;
            return DBhelper.ex(sql);
        }
       
    }
}
